# Script to produce figure 4

library(tidyverse)
library(thematic)
library(patchwork)

#Import ECB-EP monetary dialogue coding results
mon_dialogue <- read_csv("mon-dialogue.csv", 
                         col_types = cols(year = col_date(format = "%Y")))

#Pivot longer
mon_dialogue <- mon_dialogue |> 
  pivot_longer(`Critical of ECB`:`Supportive of ECB`, names_to = "type_question", values_to = "value")

#Plot line for total number of questions
p1 <- mon_dialogue |> 
  ggplot(aes(x = year, y = Total)) +
  geom_line() +
  labs(x = "Year",
       y = "Number of questions") +
  facet_wrap(vars("All structural reform questions")) +
  theme_bw(base_size = 14) +
  theme(strip.background = element_blank())

#Plot bar chart for normative questions
p2 <- mon_dialogue |> 
  ggplot(aes(x = year, y = value, fill = type_question)) +
  geom_col(position = "stack") +
  scale_fill_manual(values = okabe_ito()) +
  labs(x = "Year",
       y = NULL,
       fill = NULL) +
  facet_wrap(vars(fct_rev(type_question)), nrow = 2) +
  theme_bw(base_size = 14) +
  theme(legend.position = "none",
        strip.background = element_blank())

p1 + p2

ggsave("figures/fig4.pdf")
